package deng.java.examples;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ZipSortMap {

	public static void main(String[] args) {
		System.out.println("Unsort Map......");
		Map<String,String> unsortMap = new HashMap<String,String>();
		unsortMap.put("1", "1");
		unsortMap.put("2", "A");
		unsortMap.put("3", "2");
		unsortMap.put("4", "B");
		unsortMap.put("5", "C");
		unsortMap.put("6", "c");
		unsortMap.put("7", "b");
		unsortMap.put("8", "a");
		unsortMap.put("9", "B");
		
		List<String[]> pairList = new ArrayList<String[]>();
		for (Map.Entry<String, String> entry : unsortMap.entrySet()) {
			pairList.add(new String[] {entry.getKey(), entry.getValue() });
		}
		
		Collections.sort(pairList, new Comparator<String[]>() {
			@Override
			public int compare(String[] pairA, String[] pairB) {
				return pairA[1].compareTo(pairB[1]);
			}
		});
		
		for (String[] pair : pairList) {
			System.out.println(pair[0] + " : " + unsortMap.get(pair[0]));
		}
	}

}
